<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-param" content="_csrf">
    <meta name="csrf-token" content="MTRXUWZfd1ZUAmInITcVIF1MBiZTNxMCSXI9JwEZDxVDQ3ooJwgtIg==">
    <title></title>
    <link rel="stylesheet" href="http://g.alicdn.com/sj/dpl/1.5.1/css/sui.min.css" />
    <link rel="stylesheet" href="{{config('console.host')}}/css/unicorn.main.css" />
    <link rel="stylesheet" href="{{config('console.host')}}/css/unicorn.grey.css" class="skin-color" />
    <link href="/css/admin/bootstrap.min.css" rel="stylesheet" />

    <!--  Light Bootstrap Dashboard core CSS    -->
    <link href="/css/admin/light-bootstrap-dashboard.css" rel="stylesheet"/>
    <script src="{{config('console.host')}}/js/jquery.min.js"></script>
    <script src="http://g.alicdn.com/sj/dpl/1.5.1/js/sui.min.js"></script>
    <script src="{{config('console.host')}}/js/bootstrap.min.js"></script>
    <script src="{{config('console.host')}}/js/unicorn.js"></script>
    <script src="{{config('console.host')}}/js/unicorn.console.js"></script>
    <script src="/js/admin/jquery-resize-event.js"></script>
    <style>
        iframe#loadContent{
            max-height: 99%;
            overflow: auto;
        }
    </style>
</head>
<body>

<script type="text/javascript">
    var header_domain = "{{config('console.host')}}/public/header";
    var lefter_domain = "{{config('console.host')}}/public/lefter";
    function parseURL(url) {
        var a =  document.createElement('a');
        a.href = url;
        return {
            source: url,
            protocol: a.protocol.replace(':',''),
            host: a.hostname,
            port: a.port,
            query: a.search,
            params: (function(){
                var ret = {},
                    seg = a.search.replace(/^\?/,'').split('&'),
                    len = seg.length, i = 0, s;
                for (;i<len;i++) {
                    if (!seg[i]) { continue; }
                    s = seg[i].split('=');
                    ret[s[0]] = s[1];
                }
                return ret;
            })(),
            file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
            hash: a.hash.replace('#',''),
            path: a.pathname.replace(/^([^\/])/,'/$1'),
            relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
            segments: a.pathname.replace(/^\//,'').split('/')
        };
    }
    function LTrim(str)
    {
        var i;
        for(i=0;i<str.length;i++)
        {
            if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
        }
        str=str.substring(i,str.length);
        return str;
    }
    function RTrim(str)
    {
        var i;
        for(i=str.length-1;i>=0;i--)
        {
            if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
        }
        str=str.substring(0,i+1);
        return str;
    }
    function Trim(str)
    {
        return LTrim(RTrim(str));
    }
    $(document).ready(function(){
        var menu =[];
        $.ajax({
            type:"get",
            url:header_domain,
            dataType:"jsonp",
            jsonp:"backHeader",
            timeout:5000,
            data:"productId=579fe8571f2ee2236549c849e11251fa",
            success:function(data){
                if(data.code == 200){
                    $("#J-header").after(data.params);
                }
            }
        });

        $.ajax({
            type:"get",
            url:lefter_domain,
            dataType:"jsonp",
            jsonp:"backLefter",
            timeout:5000,
            data:{productId:"579fe8571f2ee2236549c849e11251fa"},
            success:function(data){
                console.log(data);
                if(data.code == 200){
                    $("#J-lefter").after(data.params);
                    console.log(data);
                    $('#sidebar li a').each(function (i,v) {
                        var href = Trim($(v).attr('href'));
                        if (href){
                            menu[href] = href;
                        }

                    });
                    var hash = parseURL(window.location.href)['hash'];
                    loadContent(hash);
                }
            }
        });

        function loadContent(hash) {
            var href = menu[hash]||'/web/dashboard';
            $.ajax({
                type: 'GET',
                url: '/login-status',
                dataType: 'json',
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    $('#loadContent').attr('src',href);
                },
                error: function(data){
                    location.reload();
                }
            });
//                console.log(href);
//             $('#loadContent').attr('src','/web/activity/quiz');
        }

        $(document).on('click','#sidebar li a',function () {
            var href = Trim($(this).attr('href'));
//            var hash = parseURL(window.location.href)['hash'];
//            if (hash == href){
//                return false;
//            }
            if (!href || href=="javascript:;" || href=="javascript:void(0);"){
                return false;
            }
            window.location.href = parseURL(window.location.href)['path']+'#'+href;
            loadContent(href);
            return false;

        })
        $("#loadContent").css({height:$('#content').height()});
        var iframe =  $("#loadContent")[0];
        if (iframe.attachEvent){
            iframe.attachEvent("onload", function(){
                $('title').text($(iframe).contents().find('title').text());
                var iframe_content = $(iframe).contents().find(".main-panel");
                $(iframe).css({ height: iframe_content.outerHeight( true ) });
            });
        } else {
            iframe.onload = function(){
                $('title').text($(iframe).contents().find('title').text());
                var iframe_content = $(iframe).contents().find(".main-panel");
                var height = iframe_content.outerHeight( true );
                $(iframe).css({ height: height });
            };
        }


//        function resizeIfram() {
//            var iframe = $("#loadContent");
//            var timer = setInterval(function () {
//                iframe_content = iframe.contents().find(".main-panel");
//                if (iframe_content.length >0){
//                    clearInterval(timer);
//                    iframe_content.resize(function(){
//                        var elem = $(this);
//                        console.log($(this));
//                        // Resize the IFrame.
//                        iframe.css({ height: elem.outerHeight( true ) });
//
//                        // Update the info div width and height.
////                    alert( 'IFRAME width: ' + elem.width() + ', height: ' + elem.height() );
//                        iframe.css('visibility','visible');
//                    });
//
//                }
//            },100);
//        }
//            // Append an iFrame to the page.
//
//
////            // Called once the Iframe's content is loaded.
//        $("#loadContent").load(function(){
//                resizeIfram();
//                // The Iframe's child page BODY element
//
//            });




    });
</script>
<div id="J-header"></div>
<div id="J-lefter"></div>
<div id="content" style="height: 100%;background-color: rgb(245,245,245)">
    <iframe name="loadContent" id="loadContent" style="width:100%;border:none;"></iframe>
</div>
</body>
</html>
